<include file="public@storage"/>
</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading">用户管理</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <button id="addUser" class="btn btn-info" style="margin-left: 1rem; width: 10rem" onclick="addUser()">添加用户
                        </button>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        init();
    });

    function init() {
        var url = "{:url('storage/User/getUser')}";
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: "middle",
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'id',
                field: 'id',
                visible: false
            },
            {
                title: '账号',
                field: 'user_login',
                align: "center"
            },
            {
                title: '姓名',
                field: 'user_nickname',
                align: "center"
            },
            {
                title: '角色',
                field: 'role_name',
                align: "center"
            },
            {
                title: '所属仓库',
                field: 'storage_name',
                align: "center",
                formatter: function (value, row, index) {
                    if (row.id == 1) {
                        return '所有';
                    } else {
                        return value;
                    }
                }
            },
            {
                title: '操作',
                field: 'uuid',
                align: "center",
                valign: "middle",
                formatter: function (value, row, index) {
                    html = '<a onclick="editUser(this)" href="javascript:void(0);" data-id="' + row.id + '">编辑</a>';
                    html += '&ensp;|&ensp;';
                    html += '<a onclick="deleteUser(this)" href="javascript:void(0);" data-id="' + row.id + '" data-name="' + row.user_login + '">删除</a>';
                    return html;
                }
            }
        ];
        initTable(url, columns, 'client',false);
    }

    function addUser() {
        window.location.href = "{:url('storage/User/add')}";
    }

    deleteUser = function (that) {
        var id = $(that).data('id');
        var name = $(that).data('name');
        if (id == 1) {
            layer.msg('admin账号不可删除');
        } else {
            var data = {
                id: id
            };
            var tip = '是否删除用户' + name;
            var url = "{:url('User/deleteUser')}";
            reviseTable(tip, url, data);
        }
    };

    editUser = function (that) {
        var id = $(that).data('id');
        if (id == 1) {
            layer.msg('admin账号不可编辑');
        } else {
            window.location.href = '{:url("storage/User/edit")}?id=' + id;
        }
    };
</script>
</html>